package org.example.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.domain.User;
import org.example.dto.UserDTO;
import org.example.dto.UserLoginDTO;
import org.example.dto.UserPageQueryDTO;
import org.example.mapper.UserMapper;
import org.example.result.PageResult;
import org.example.service.UserService;
import org.example.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.sound.sampled.Port;

/**
 * @author 19816
 * @description 针对表【sys_user】的数据库操作Service实现
 * @createDate 2024-05-22 14:08:03
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    public User getUser(UserLoginDTO user) {
        return userMapper.getUser(user);
    }

    @Override
    public Integer add(User user) {
        return userMapper.add(user);
    }

    @Override
    public PageResult listAll(UserPageQueryDTO userPageQueryDTO) {
        PageHelper.startPage(userPageQueryDTO.getPageNum(), userPageQueryDTO.getPageSize());
        Page<UserVO> page = userMapper.listAll(userPageQueryDTO);
        return PageResult.builder()
                .recodes(page)
                .total(page.getTotal())
                .build();
    }

    //修改信息
    @Override
    public boolean update(UserDTO userDTO) {
        return userMapper.update(userDTO);
    }

    /**
     * 获取用户名
     *
     * @param id
     * @return
     */
    public String getUserName(String id) {
        return userMapper.getUserName(id);
    }

}




